<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Coxpcall -  Coroutine Safe xpcall and pcall</title>
	<link rel="stylesheet" href="doc.css" type="text/css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>

<body>

<div id="container">

<div id="product">
	<div id="product_logo"><a href="http://keplerproject.github.io/coxpcall/">
		<img alt="coxpcall logo" src="coxpcall.png" width="128" height="128"/></a>
	</div>
	<div id="product_name"><big><strong>Coxpcall</strong></big></div>
	<div id="product_description">Coroutine-safe <code>xpcall</code> and <code>pcall</code> versions</div>
</div> <!-- id="product" -->

<div id="main">

<div id="navigation">
<h1>Coxpcall</h1>
	<ul>
		<li><strong>Home</strong>
		<ul>
			<li><a href="index.html#over">Overview</a></li>
			<li><a href="index.html#status">Status</a></li>
			<li><a href="index.html#download">Download</a></li>
			<li><a href="index.html#reference">Reference</a></li>
			<li><a href="index.html#credits">Credits</a></li>
		</ul>
		</li>
		<li><a href="http://keplerproject.github.io/coxpcall/">Project</a>
		<ul>
			<li><a href="https://github.com/keplerproject/coxpcall/issues">Bug Tracker</a></li>
			<li><a href="https://github.com/keplerproject/coxpcall">Source code</a></li>
		</ul>
		</li>
		<li><a href="license.html">License</a></li>
	</ul>
</div> <!-- id="navigation" -->

<div id="content">

<h2><a name="over"></a>Overview</h2>

<p>Coxpcall encapsulates the protected calls with a coroutine based loop,
so errors can be dealed without the usual <code>pcall</code>/<code>xpcall</code>
issues with coroutines.
</p>

<p>Using Coxpcall usually consists in simply loading the module and then
replacing Lua <code>pcall</code>, <code>xpcall</code> and <code>coroutine.running</code> 
by <code>copcall</code>, <code>coxpcall</code>, and <code>running</code>.</p>

<p>Coxpcall is free software and uses the same
<a href="license.html">license</a> as Lua 5.1 and 5.2.
</p>

<h2><a name="status"></a>Status</h2>

<p>It supports Lua 5.1, 5.2 and 5.3. Lua 5.2 was extended with the Coxpcall 
functionality and hence coxpcall is no longer required. The
5.2+ compatibility by coxpcall means that it maintains backward compatibility
while using the built-in implementation.</p>

<h2><a name="download"></a>Download</h2>

<p>
You can get Coxpcall using <a href="http://luarocks.org">LuaRocks</a>:
</p>

<pre class="example">
luarocks install coxpcall
</pre>

<p>
See also its 
<a href="https://github.com/keplerproject/coxpcall">GitHub</a> page.
</p>

<h2><a name="reference"></a>Reference</h2>

<p>Coxpcall module offers three functions that reproduce the behaviour of
<code>pcall</code>, <code>xpcall</code>, and  <code>coroutine.running</code>:</p>

<pre class="example">
local coxpcall = require "coxpcall"
</pre>

<dl>
	<dt><strong><code>coxpcall.xpcall(f, err)</code></strong></dt>
	<dd>Offers the same functionality as Lua <code>xpcall(f, err)</code>,
	but calls the error handler <em>after</em> the error unwinds the stack,
	so that it's impossible to gather more information about the error.
	To compensate, if the error is a string, stack trace is appended to it.
	Also set as global <code>coxpcall</code>.</dd>
	
	<dt><strong><code>coxpcall.pcall(f, ...)</code></strong></dt>
	<dd>Offers the same functionality as Lua <code>pcall(f, ...)</code>.
	Also set as global <code>copcall</code>.</dd>

	<dt><strong><code>coxpcall.running([coro])</code></strong></dt>
        <dd>Because <code>coxpcall</code> and <code>copcall</code> run the function to protect 
        inside a new coroutine, <code>coroutine.running()</code> will return an unexpected
        coroutine when used inside the protected function. If the coroutine <code>coro</code> was 
        created by the coxpcall module, then <code>running(coro)</code> will return the original 
        coroutine that created it. If <code>coro</code> is not provided, it will default to the
        currently running coroutine.</dd>
</dl>

<h2><a name="credits"></a>Credits</h2>

<p>
Coxpcall was designed and implemented by Roberto Ierusalimschy and
Andr&eacute; Carregal with the colaboration of Thomas Harning Jr., Ignacio Burgue&ntilde;o,
Gary NG and F&aacute;bio Mascarenhas as part of the
<a href="https://github.com/keplerproject">Kepler Project</a> which holds its copyright.
</p>

</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
</body>
</html>

